import {defineConfig} from "vite"
import vue from "@vitejs/plugin-vue"
import path from "path"
import Unocss from "unocss/vite"
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import {ElementPlusResolver} from "unplugin-vue-components/resolvers"
import ElementPlus from "unplugin-element-plus/vite"

// https://vite.dev/config/
export default defineConfig({
  resolve: {
    alias: [
      {
        find: "@",
        replacement: path.resolve(__dirname, "src")
      }
    ]
  },
  plugins: [
    vue(),
    Unocss(),
    AutoImport({
      // api
      imports: ["vue", "vue-router", "pinia"],
      resolvers: [ElementPlusResolver()],
      eslintrc: {
        enabled: false // eslint 生成得配置 1次
      }
    }),
    Components({
      // 组件
      resolvers: [ElementPlusResolver()],
      // 所有组件自动加载
      dirs: ["src/components", "src/layout/components", "src/views/**/components"]
    }),
    ElementPlus({})
  ],
  server: {
    proxy: {
      "/dev-api": {
        target: "http://localhost:5173",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev-api/, "/api")
      }
    }
  }
})
